//
// Created by yyl on 2021/11/30.
//

#include "VideoShader.h"

void VideoShader::Init() {
    if (!isInit) {
        isInit = true;
//        glEnable(GL_DEPTH_TEST);
//        auto str = glGetString(GL_EXTENSIONS);
//        LOGI("查看设备所支持的扩展:%s", str);
        createVAO();
        createVBO();
        createEBO();
        createShaderFromFile();
        createTexture();

        LOGI("初始化完成VideoShader:Init");
    }
}

void VideoShader::Draw(int screenW, int screenH) {
    LOGI("VideoShader:Draw");
//    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
    glClear(GL_COLOR_BUFFER_BIT);
    glClearColor(0.0, 0.0, 0.0, 1.0);
    if (programID) {
        glUseProgram(programID);
        glm::mat4 pvm = MatrixConvert::convertOrtho(transformMatrix);
        GLUtils::setMat4(programID, "PVM", pvm);
        bindTextureImage();
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, textureID);
        glBindVertexArray(VAO);
        //EBO填充
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
        //解绑VAO
        glBindVertexArray(GL_NONE);
        glUseProgram(GL_NONE);
    }
}
